<template>
  <div>
    <div>
      <div class="header-h display-flex ai-center">
        <div class="bgImg">
          <img :src="model.bgImg" alt="">
        </div>
        <router-link to="/" tag="div" class="icondiv">
          <i class="iconfont icon-jiantou3 p-2" ></i>
        </router-link>
        <div class="avatar">
          <img :src="model.avatar" alt="">
        </div>
      </div>
      <div class="header-b pt-6">
        <div class="display-flex jc-center ai-center pl-1" @click="toggleShopShow">
          <span class="brand">品牌</span>
          <div class="font-weight font-title pl-2 pr-2" >{{model.name}}</div>
          <div class="trangle" ></div>
        </div>
        <div class="display-flex jc-center font-xs mt-1">
          <span>{{model.score}}</span>
          <span class="pl-2">{{`月做${model.sellCount}单`}}</span>
          <span class="pl-2">{{model.description}}</span>
          <span class="pl-1">{{`约${model.deliveryTime}分钟`}}</span>
          <span class="pl-2">{{`距离${model.distance}`}}</span>
        </div>
        <div v-if="model.supports[0]" class="discount display-flex jc-center mt-1 ai-center " @click="toggleSupportShow">
          <div class="name">{{model.supports[0].name}}</div>
          <span class="font-xs pl-2 grey-2 pr-4">{{model.supports[0].content}}</span>
          <div class="display-flex ai-center font-xs">
            <span class="grey-2 pr-1 pl-1">{{`${model.supports.length}个优惠`}}</span>
            <div class="downTrangle"></div>
          </div>
        </div>
      </div>
<!--      动画过渡-->
      <transition name="fade">
        <div v-show="shopShow" class="storeShop">
          <div class="storeShopCard">
              <div class="display-flex jc-center ai-center pl-1">
                <span class="brand">品牌</span>
                <div class="font-weight font-title pl-2 pr-2">{{model.name}}</div>
              </div>
              <div class="display-flex jc-around text-center mt-2">
                <div>
                  <h3 class="black">{{model.score}}</h3>
                  <p class="grey-1 font-s">评分</p>
                </div>
                <div>
                  <h3 class="black">{{model.sellCount}}</h3>
                  <p class="grey-1 font-s">月售</p>
                </div>
                <div>
                  <h3 class="black">{{model.description}}</h3>
                  <p class="grey-1 font-s">{{`约${model.deliveryTime}分钟`}}</p>
                </div>
                <div>
                  <h3 class="black">{{model.deliveryPrice}}</h3>
                  <p class="grey-1 font-s">配送费用</p>
                </div>
                <div>
                  <h3 class="black">{{model.distance}}</h3>
                  <p class="grey-1 font-s">距离</p>
                </div>
              </div>
              <div class="display-flex jc-center ai-center mt-3">
                <div class="display-flex">
                  <div class="liner-left"></div>
                  <div class="notice grey-1 font-s pl-2 pr-2">公告</div>
                  <div class="liner-right"></div>
                </div>
              </div>
              <div class="p-3">
                <p class="font-m black">{{model.bulletin}}</p>
              </div>
            </div>
          <div class="close text-center mt-3" @click="toggleShopShow">
              <i class="iconfont icon-guanbi"></i>
            </div>
        </div>
      </transition>

      <transition name="fade">
        <div class="support pr-2" v-show="supportShow">
          <div class="supportShowCard">
            <i class="iconfont icon-icon-close" @click="toggleSupportShow"></i>
            <h2 class="text-center pt-2">优惠活动</h2>
            <ul class="sellActive">
              <li v-for="(item,i) in model.supports" :key="i" class="mt-2">
                <span class="name icon" :class="{green:item.type === 0,red:item.type === 1,orange:item.type === 2}">{{item.name}}</span>
                <span class="font-m black pl-2 grey-2 pr-4">{{item.content}}</span>
              </li>
            </ul>
          </div>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
  export default {
    name: "ShopHeader",
    data(){
      return {
        model:{
          supports:{name:'',content:'',type:Number}
        },
        shopShow:false,
        showLeave:false,
        supportShow:false
      }
    },
    computed:{
      getImgUrl(){
        return this.model.bgImg
      }
    },
    methods: {
      async getGoodsData(){
        const res = await this.$http.get('/info')
        this.model = res.data
      },
      toggleShopShow(){
        this.shopShow = !this.shopShow
      },
      toggleSupportShow(){
        this.supportShow = !this.supportShow

      },
      hello(){
        console.log('ok')
      }
    },
    created() {
      this.getGoodsData()
    }
  }
</script>

<style lang="scss" scoped>
  .header-h{
    position: relative;
    height: 50px;
    &::before{
      content: '';
      position: absolute;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
      background-color: rgba(119,103,137,0.43);
      z-index: -1;
    }
    .bgImg{
      position: absolute;
      height: 50px;
      overflow: hidden;
      width: 100%;
      img{
        position: absolute;
        top: 0;
        z-index: -2;
        height: 95px;
        width: 100%;
      }
    }
    .icondiv{
      z-index: 80;
      .iconfont{
        font-size: 20px;
        color: #fff;
        padding: 10px 10px;
      }
    }
    .avatar{
      position: absolute;
      left: 50%;
      margin-left: -33px;
      top: 10px;
      img{
        width: 66px;
        height: 66px;
        z-index: 2;
      }
    }
  }
  .header-b{
    background-color: #fff;
    .brand{
      background-image: linear-gradient(to right,#fff100,#ffe339);
      font-size: 12px;
      padding: 0px 4px 2px 4px;
    }
    .trangle{
      width: 0;
      height: 0;
      border-top: 7px solid transparent;
      border-left: 7px solid #333333;
      border-right: 7px solid transparent;
      border-bottom: 7px solid transparent;
    }
    .discount{
      border: 1px solid #eeeeee;
      padding: 2px 0;
      margin-left: 32px;
      margin-right: 32px;
      .name{
        background-color: #70bc46;
        color: #fff;
        font-weight: 700;
        font-size: 9px;
        padding: 0 2px;
        text-align: center;
      }
      .downTrangle{
        width: 0;
        height: 0;
        margin-top: 4px;
        border-bottom: 4px solid transparent;
        border-top: 4px solid #666666;
        border-left: 4px solid transparent;
        border-right: 4px solid transparent;
      }
    }
  }
  .storeShop{
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: rgba(0,0,0,0.4);
    z-index: 99;
    .storeShopCard{
      background-color: #fff;
      border-radius: 10px;
      position: absolute;
      left: 50%;
      margin-left: -170px;
      width: 340px;
      height: 200px;
      top: 50%;
      margin-top: -127px ;
      padding-top: 20px;
      .brand{
        background-image: linear-gradient(to right,#fff100,#ffe339);
        font-size: 12px;
        padding: 0px 4px 2px 4px;
      }
      .liner-left,
      .liner-right{
        width:27px;
        height: 1px;
        margin-top: 9px;
      }
      .liner-left{
        background: linear-gradient(to right, #fff, #999); /* 标准的语法（必须放在最后） */
      }
      .liner-right{
        background: linear-gradient(to right, #999, #fff); /* 标准的语法（必须放在最后） */
      }
    }
    .close{
      .iconfont{
        color: #eeeeee;
        font-size: 28px;
        z-index: 9;
        position: absolute;
        bottom: 20%;
        left: 50%;
        margin-left: -14px;
      }
    }
  }
  .support{
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
    background-color: rgba(0,0,0,0.4);
    z-index: 999;
    .supportShowCard{
      position: absolute;
      bottom: 0;
      height: 240px;
      background-color: #f5f5f5;
      width: 100%;
      z-index: 99;

      .iconfont{
        font-size: 20px;
        float: right;
        color: #333333;
      }
      .icon{
        color: #fff;
        font-size: 13px;
        padding: 0 5px;
        text-align: center;
        border-radius: 2px;
        &.green{
          background-color: #70bc46;
        }
        &.red{
          background-color: #f07373;
        }
        &.orange {
          background-color: #f1884f;
        }
      }
      .sellActive{
        width: 100%;
        overflow-y: scroll;
        height: 160px;
        padding: 0px 30px;
      }
    }

  }
  .fade-enter-active, .fade-leave-active {
    transition: 1s;
    opacity: 1;
  }
  .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
    opacity: 0;
  }
</style>
